package com.zx.notification.producer.controller;

import com.zx.core.utils.JsonStrUtils;
import com.zx.core.wrapper.ObjectWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.notification.common.param.SystemNotificationsParam;
import com.zx.notification.producer.service.ISystemNotificationsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 系统通知控制器 <br>
 * create: 2025-10-15
 * </p>
 *
 * @author zhou  xun
 */
@RestController
@RequestMapping("/system-notifications")
@RequiredArgsConstructor
public class SystemNotificationsController {

    private final ISystemNotificationsService iSystemNotificationsService;


    /**
     * 新增系统通知
     *
     * @param paramJsonStr 系统通知信息JSON字符串
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "新增系统通知")
    @PostMapping("/addSystemNotification")
    public ResponseWrapper addSystemNotification(@RequestBody String paramJsonStr) {
        // 将JSON字符串转换为参数对象
        ObjectWrapper<SystemNotificationsParam> objectWrapper = JsonStrUtils.checkParseObject(paramJsonStr, SystemNotificationsParam.class);
        if (objectWrapper.verifyFail()) {
            ResponseWrapper result = new ResponseWrapper();
            result.fail("参数解析失败: " + objectWrapper.getMsg());
            return result;
        }
        SystemNotificationsParam systemNotificationsParam = objectWrapper.getData();
        return iSystemNotificationsService.addSystemNotification(systemNotificationsParam);
    }

    /**
     * 重新发送系统通知
     *
     * @param notificationId 通知ID
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "重新发送系统通知")
    @PostMapping("/resendNotification")
    public ResponseWrapper resendNotification(@RequestParam("notificationId") String notificationId) {
        return iSystemNotificationsService.resendNotification(notificationId);
    }
}